package com.lx.myapplication2.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lx.myapplication2.R;
import com.lx.myapplication2.pojo.Music;

import java.util.List;

public class MyAdapter extends BaseAdapter {

    private Context context;
    private List<Music> musicList;

    public MyAdapter(Context context, List<Music> musicList) {
        this.context = context;
        this.musicList = musicList;
    }

    @Override
    public int getCount() {
        return musicList.size();
    }

    @Override
    public Object getItem(int position) {
        return musicList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        convertView = View.inflate(context, R.layout.item_music, null);
        TextView musicId = convertView.findViewById(R.id.music_id_tv);
        musicId.setText(musicList.get(position).getId());
        TextView musicName = convertView.findViewById(R.id.music_name_tv);
        musicName.setText(musicList.get(position).getName());
        TextView musicArtist = convertView.findViewById(R.id.music_artist_tv);
        musicArtist.setText(musicList.get(position).getMusicArtist());
        return convertView;
    }
}
